<?php

class Mpages extends CI_Model {
	
	public $table = 'tbl_page';
	public $pri_key="page_id";
	function __construct()
	{
		parent::__construct();

	}
	function load_page_cat()
	{
		$this->db->where('cat_status = 1');
		$this->db->where('cat_lang = 1');
		$this->db->order_by('cat_id','ASC');
		$query = $this->db->get('tbl_page_cat');
		if($query->num_rows() > 0)
		{
			return $query->result_array();
		}
		return false;
	}
	public function get_page($id="",$lang,$cate="",$num='',$off='',$sort="DESC")
	{
		if($off != '')
				$this->db->limit($off,$num);
		if($id != "")
			$this->db->where($this->pri_key,$id);
		if($cate != "")
			$this->db->where('page_cat',$cate);
		
		$this->db->where('page_lang',$lang);
		$this->db->order_by($this->pri_key." $sort");
		$query = $this->db->get($this->table);
		if($query->num_rows() >0)
			return $query->result_array();
		return false;
	}
		public function del_item($id)
	{
		if($id > 0)
		{
		$this->db->where($this->pri_key, $id);
		$this->db->delete($this->table); 
		}
	}
	
	public function insert($data)
	{
		if($this->db->insert($this->table,$data))
			return true;
		
		return false;
	}
	public function update($data,$id,$lang)
	{
		$where = $this->pri_key." =".$id." and page_lang= $lang";
		if($this->db->update($this->table,$data,$where))
			return true;
		return false;
	
	}
	public function info_form_id($id)
	{
		if(is_numeric($id) && $id !="")
		{
			$this->db->where($this->pri_key.' =',$id);
			$this->db->order_by("page_lang ");
			return $this->db->get($this->table)->result_array();
		}
		else
			return false;
	}
	public function list_data($id=0, $num,$off)
	{
		
		if($this->db->count_all($this->table) >0)
			//return $this->db->get($this->table)->result_array();
			{
				$this->db->limit($off,$num);
		$this->db->where('page_cat = ',$id);
		$this->db->join("tbl_page_cat" , "cat_id = page_cat and cat_lang = 1" );
		
		$this->db->order_by($this->pri_key." DESC");
				return $this->db->get($this->table)->result_array();
			}
		return false;
	}
	// dem so record 
	function count_by_cat($id)
	{
		
		$this->db->where("page_cat = $id");
		$query = $this->db->get($this->table);
		return $query->num_rows();
	}
	function count_all()
	{
		return $this->db->count_all_results($this->table);
	}
	public function get_last_id()
	{
		$this->db->select($this->pri_key);
		$this->db->order_by($this->pri_key." DESC");
			return $this->db->get($this->table)->row_array();
	}
	
	public function get_prod_detail($id="",$lang,$cate="")
	{
		if($id != "")
			$this->db->where($this->pri_key,$id);
		if($cate != "")
			$this->db->where('page_cat',$cate);
		
		$this->db->where('page_lang',$lang);
			$this->db->order_by($this->pri_key." DESC");
		$query = $this->db->get($this->table);
		if($query->num_rows() >0)
			return $query->row_array();
		return false;
	}
	
	public function info_detail($id,$table)
	{

		$this->db->where($this->pri_key, $id);
		return $this->db->get($table)->row_array();
	}
	public function info_from_id($id,$table)
	{
		if($table == 'tbl_page')
			$pri_key=$this->pri_key;
		else
			$pri_key=$this->pri_key;
		
		
		if(is_numeric($id) && $id !="")
		{
			$this->db->where($pri_key.' =',$id);
			return $this->db->get($table)->result_array();
		}
		else
			return false;
	}
	function delete()

	{

		if (isset($_POST['checkbox1']))

		{

			foreach($_POST['checkbox1'] as $id) 
			{
				$row = $this->info_from_id($id,$this->table);
				$row = $row[0];
				if (!empty($row['page_image'])) unlink("./upload/news/".$row['page_image']);
				$this->db->where($this->pri_key, $id);
				$this->db->delete($this->table); 
			
			}			

		}

	}
	public function info_image($catID)
	{

		if($this->db->count_all("tbl_page") >0)
		{
			$this->db->where('page_cat',$catID);
			$this->db->order_by("page_id","DESC");
			return $this->db->get("tbl_page")->row_array();
			
		}
	}


}//end model class





/* End of file mhumans.php */

/* Location: ./system/application/models/mhumans.php */

?>